package com.template.app.api;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.LazyDynaBean;
import org.cn.template.component.domain.API;
import org.cn.template.component.utils.SimpleDateUtil;
import org.cn.template.component.web.control.BaseAPIControl;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.template.app.model.Category;
import com.template.app.service.ICategoryService;



/**
 * 
 * @author SongJian 491835898@QQ.COM
 * @date 2015-09-27 中秋节
 * @see org.cn.template.component.web.control.BaseAPIControl
 * 
 * demo : http://localhost:8080/api/categoryList.html
 */
@RequestMapping(value = "/api")
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Controller
public class StandardAPI extends BaseAPIControl{

	@Resource
	private ICategoryService categoryService;
	
	@RequestMapping("/categoryList")
	public API getCategoryList(HttpServletRequest request,ModelAndView model){
		API api = new API();
		api.setCommand("/api/categoryList");
		api.setContent(JSON.toJSONString(new Category(1L,"demo 分类")));
		return api;
	}
	
	
	@RequestMapping(value = "/activity/list/{group}/{year}/{month}/{day}")
	public API todayActivityList(@PathVariable String group, @PathVariable Integer year, @PathVariable Integer month,
			@PathVariable Integer day) {
		System.out.println(year);
		if (dataCache.containsKey(group)) {
			cacheTimer.get(group);
		}
		return null;
	}
	
	
	/*
	 * DynaBean是一个接口类，可以由LazyDynaBean生成一个DynaBean的实例，用于处理符合javaBean规则的bean，
	 * 相当于一个可以制作出各种形状棒冰的万能模型。 
	 * 
	 * DynaBean的内部实现简介，LazyDynaBean是DynaBean的实现类.
	 * 最核心的思路是用一个Map保存了javaBean的各个属性名和属性值
	 * ，将属性名和属性值分别放在Map型的key和value当中。另外，LazyDynaBean当中还有一个重要的DynaClass类
	 * ，用于将各个key的属性名和属性类型（String型、int型等）保存到DynaProperty当中。
	 * 
	 */
	@RequestMapping(value = "/activity/info/{group}/{id}")
	public DynaBean acrivityInfo() {
		// dynaBean.set(String property, String value); //通过指定属性名，设置属性值。
		// dynaBean.get(String property); //通过指定属性名，获得属性值。
		DynaBean dynaBean = new LazyDynaBean();
		dynaBean.set("starttime", SimpleDateUtil.curTimeMillis());
		return dynaBean;
	}
	
}
